using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VQGUETEKL
    {
        public DataRow Convert2QGUETEKL(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryQGUETEKL(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["QGKMANDANT"] = " ".PadRight(2 ); 
         dwReturn["QGKGKREGEL"] = " ".PadRight(8 ); 
         dwReturn["QGKGUETEKL"] = " ".PadRight(8 ); 
         dwReturn["QGKAENZL"] = " ".PadRight(0 ); 
         dwReturn["QGKAENB"] = " ".PadRight(8 ); 
         dwReturn["QGKAEND"] = " ".PadRight(0 ); 
         dwReturn["QGKNEUB"] = " ".PadRight(8 ); 
         dwReturn["QGKNEUD"] = " ".PadRight(0 ); 
         dwReturn["QGKBEZ"] = " ".PadRight(30 ); 
         dwReturn["QGKSTATUS"] = " ".PadRight(1 ); 
         dwReturn["QGKZENSUR"] = " ".PadRight(2 ); 
         dwReturn["QGKRUECKENF"] = " ".PadRight(1 ); 
         dwReturn["QGKMTR"] = " ".PadRight(0 ); 
         dwReturn["QGKVONMTR"] = " ".PadRight(0 ); 
         dwReturn["QGKBISMTR"] = " ".PadRight(0 ); 
         dwReturn["QGKBRT"] = " ".PadRight(8 ); 
         dwReturn["QGKVONBRT"] = " ".PadRight(8 ); 
         dwReturn["QGKBISBRT"] = " ".PadRight(8 ); 
         dwReturn["QGKSCHAUUMF1"] = " ".PadRight(1 ); 
         dwReturn["QGKSCHAUUMF2"] = " ".PadRight(1 ); 
         dwReturn["QGKZONENERF"] = " ".PadRight(1 ); 
         dwReturn["QGKMAXANZN"] = " ".PadRight(0 ); 
         dwReturn["QGKMAXANZA"] = " ".PadRight(0 ); 
         dwReturn["QGKMINLGA"] = " ".PadRight(0 ); 
         dwReturn["QGKABSCHNERL"] = " ".PadRight(1 ); 
         dwReturn["QGKSCHNVGUET"] = " ".PadRight(0 ); 
         dwReturn["QGKMINABSTR"] = " ".PadRight(0 ); 
         dwReturn["QGKMINABSTF"] = " ".PadRight(0 ); 
         dwReturn["QGKBISPKTF"] = " ".PadRight(0 ); 
         dwReturn["QGKBISSTRKF"] = " ".PadRight(0 ); 
         dwReturn["QGKBISFPKT"] = " ".PadRight(0 ); 
         dwReturn["QGKMINABSTSCH"] = " ".PadRight(0 ); 
         dwReturn["QGKSTKANF"] = " ".PadRight(1 ); 
         dwReturn["QGKSTKENDE"] = " ".PadRight(1 ); 
         dwReturn["QGKABSCHNANF"] = " ".PadRight(1 ); 
         dwReturn["QGKABSCHNENDE"] = " ".PadRight(1 ); 
         dwReturn["QGKMARK"] = " ".PadRight(1 ); 
         dwReturn["QGKRNVGFPKT"] = " ".PadRight(0 ); 
         dwReturn["QGKETKTYP"] = " ".PadRight(2 ); 
         dwReturn["QGKAUFM"] = " ".PadRight(2 ); 
         dwReturn["QGKVPACK"] = " ".PadRight(4 ); 
         dwReturn["QGKFVGUET"] = " ".PadRight(1 ); 
         dwReturn["QGKMSCHNTOL"] = " ".PadRight(1 ); 
         dwReturn["QGKFILLER"] = " ".PadRight(37 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapQGUETEKL(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveQGUETEKL(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryQGUETEKL(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapQGUETEKL(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertQGUETEKL(dwLocal, ITXDBVERSION);
            }
            UpdateQGUETEKL(dwLocal);
        }
        public void InsertQGUETEKL(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO QGUETEKL(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryQGUETEKL(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM QGUETEKL WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM QGUETEKL  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "QGUETEKL";
            Return = Result;
            return Return;
        }
        public void DeleteQGUETEKL(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM QGUETEKL   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateQGUETEKL(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE QGUETEKL SET "
                    +"QGKMANDANT= :QGKMANDANT,"
                    +"QGKGKREGEL= :QGKGKREGEL,"
                    +"QGKGUETEKL= :QGKGUETEKL,"
                    +"QGKAENZL= :QGKAENZL,"
                    +"QGKAENB= :QGKAENB,"
                    +"QGKAEND= :QGKAEND,"
                    +"QGKNEUB= :QGKNEUB,"
                    +"QGKNEUD= :QGKNEUD,"
                    +"QGKBEZ= :QGKBEZ,"
                    +"QGKSTATUS= :QGKSTATUS,"
                    +"QGKZENSUR= :QGKZENSUR,"
                    +"QGKRUECKENF= :QGKRUECKENF,"
                    +"QGKMTR= :QGKMTR,"
                    +"QGKVONMTR= :QGKVONMTR,"
                    +"QGKBISMTR= :QGKBISMTR,"
                    +"QGKBRT= :QGKBRT,"
                    +"QGKVONBRT= :QGKVONBRT,"
                    +"QGKBISBRT= :QGKBISBRT,"
                    +"QGKSCHAUUMF1= :QGKSCHAUUMF1,"
                    +"QGKSCHAUUMF2= :QGKSCHAUUMF2,"
                    +"QGKZONENERF= :QGKZONENERF,"
                    +"QGKMAXANZN= :QGKMAXANZN,"
                    +"QGKMAXANZA= :QGKMAXANZA,"
                    +"QGKMINLGA= :QGKMINLGA,"
                    +"QGKABSCHNERL= :QGKABSCHNERL,"
                    +"QGKSCHNVGUET= :QGKSCHNVGUET,"
                    +"QGKMINABSTR= :QGKMINABSTR,"
                    +"QGKMINABSTF= :QGKMINABSTF,"
                    +"QGKBISPKTF= :QGKBISPKTF,"
                    +"QGKBISSTRKF= :QGKBISSTRKF,"
                    +"QGKBISFPKT= :QGKBISFPKT,"
                    +"QGKMINABSTSCH= :QGKMINABSTSCH,"
                    +"QGKSTKANF= :QGKSTKANF,"
                    +"QGKSTKENDE= :QGKSTKENDE,"
                    +"QGKABSCHNANF= :QGKABSCHNANF,"
                    +"QGKABSCHNENDE= :QGKABSCHNENDE,"
                    +"QGKMARK= :QGKMARK,"
                    +"QGKRNVGFPKT= :QGKRNVGFPKT,"
                    +"QGKETKTYP= :QGKETKTYP,"
                    +"QGKAUFM= :QGKAUFM,"
                    +"QGKVPACK= :QGKVPACK,"
                    +"QGKFVGUET= :QGKFVGUET,"
                    +"QGKMSCHNTOL= :QGKMSCHNTOL,"
                    +"QGKFILLER= :QGKFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("QGKMANDANT", OracleType.NVarChar).Value = dwData["QGKMANDANT"].ToString(); 
          or1.Parameters.Add("QGKGKREGEL", OracleType.NVarChar).Value = dwData["QGKGKREGEL"].ToString(); 
          or1.Parameters.Add("QGKGUETEKL", OracleType.NVarChar).Value = dwData["QGKGUETEKL"].ToString(); 
          or1.Parameters.Add("QGKAENZL", OracleType.NVarChar).Value = dwData["QGKAENZL"].ToString(); 
          or1.Parameters.Add("QGKAENB", OracleType.NVarChar).Value = dwData["QGKAENB"].ToString(); 
          or1.Parameters.Add("QGKAEND", OracleType.NVarChar).Value = dwData["QGKAEND"].ToString(); 
          or1.Parameters.Add("QGKNEUB", OracleType.NVarChar).Value = dwData["QGKNEUB"].ToString(); 
          or1.Parameters.Add("QGKNEUD", OracleType.NVarChar).Value = dwData["QGKNEUD"].ToString(); 
          or1.Parameters.Add("QGKBEZ", OracleType.NVarChar).Value = dwData["QGKBEZ"].ToString(); 
          or1.Parameters.Add("QGKSTATUS", OracleType.NVarChar).Value = dwData["QGKSTATUS"].ToString(); 
          or1.Parameters.Add("QGKZENSUR", OracleType.NVarChar).Value = dwData["QGKZENSUR"].ToString(); 
          or1.Parameters.Add("QGKRUECKENF", OracleType.NVarChar).Value = dwData["QGKRUECKENF"].ToString(); 
          or1.Parameters.Add("QGKMTR", OracleType.NVarChar).Value = dwData["QGKMTR"].ToString(); 
          or1.Parameters.Add("QGKVONMTR", OracleType.NVarChar).Value = dwData["QGKVONMTR"].ToString(); 
          or1.Parameters.Add("QGKBISMTR", OracleType.NVarChar).Value = dwData["QGKBISMTR"].ToString(); 
          or1.Parameters.Add("QGKBRT", OracleType.NVarChar).Value = dwData["QGKBRT"].ToString(); 
          or1.Parameters.Add("QGKVONBRT", OracleType.NVarChar).Value = dwData["QGKVONBRT"].ToString(); 
          or1.Parameters.Add("QGKBISBRT", OracleType.NVarChar).Value = dwData["QGKBISBRT"].ToString(); 
          or1.Parameters.Add("QGKSCHAUUMF1", OracleType.NVarChar).Value = dwData["QGKSCHAUUMF1"].ToString(); 
          or1.Parameters.Add("QGKSCHAUUMF2", OracleType.NVarChar).Value = dwData["QGKSCHAUUMF2"].ToString(); 
          or1.Parameters.Add("QGKZONENERF", OracleType.NVarChar).Value = dwData["QGKZONENERF"].ToString(); 
          or1.Parameters.Add("QGKMAXANZN", OracleType.NVarChar).Value = dwData["QGKMAXANZN"].ToString(); 
          or1.Parameters.Add("QGKMAXANZA", OracleType.NVarChar).Value = dwData["QGKMAXANZA"].ToString(); 
          or1.Parameters.Add("QGKMINLGA", OracleType.NVarChar).Value = dwData["QGKMINLGA"].ToString(); 
          or1.Parameters.Add("QGKABSCHNERL", OracleType.NVarChar).Value = dwData["QGKABSCHNERL"].ToString(); 
          or1.Parameters.Add("QGKSCHNVGUET", OracleType.NVarChar).Value = dwData["QGKSCHNVGUET"].ToString(); 
          or1.Parameters.Add("QGKMINABSTR", OracleType.NVarChar).Value = dwData["QGKMINABSTR"].ToString(); 
          or1.Parameters.Add("QGKMINABSTF", OracleType.NVarChar).Value = dwData["QGKMINABSTF"].ToString(); 
          or1.Parameters.Add("QGKBISPKTF", OracleType.NVarChar).Value = dwData["QGKBISPKTF"].ToString(); 
          or1.Parameters.Add("QGKBISSTRKF", OracleType.NVarChar).Value = dwData["QGKBISSTRKF"].ToString(); 
          or1.Parameters.Add("QGKBISFPKT", OracleType.NVarChar).Value = dwData["QGKBISFPKT"].ToString(); 
          or1.Parameters.Add("QGKMINABSTSCH", OracleType.NVarChar).Value = dwData["QGKMINABSTSCH"].ToString(); 
          or1.Parameters.Add("QGKSTKANF", OracleType.NVarChar).Value = dwData["QGKSTKANF"].ToString(); 
          or1.Parameters.Add("QGKSTKENDE", OracleType.NVarChar).Value = dwData["QGKSTKENDE"].ToString(); 
          or1.Parameters.Add("QGKABSCHNANF", OracleType.NVarChar).Value = dwData["QGKABSCHNANF"].ToString(); 
          or1.Parameters.Add("QGKABSCHNENDE", OracleType.NVarChar).Value = dwData["QGKABSCHNENDE"].ToString(); 
          or1.Parameters.Add("QGKMARK", OracleType.NVarChar).Value = dwData["QGKMARK"].ToString(); 
          or1.Parameters.Add("QGKRNVGFPKT", OracleType.NVarChar).Value = dwData["QGKRNVGFPKT"].ToString(); 
          or1.Parameters.Add("QGKETKTYP", OracleType.NVarChar).Value = dwData["QGKETKTYP"].ToString(); 
          or1.Parameters.Add("QGKAUFM", OracleType.NVarChar).Value = dwData["QGKAUFM"].ToString(); 
          or1.Parameters.Add("QGKVPACK", OracleType.NVarChar).Value = dwData["QGKVPACK"].ToString(); 
          or1.Parameters.Add("QGKFVGUET", OracleType.NVarChar).Value = dwData["QGKFVGUET"].ToString(); 
          or1.Parameters.Add("QGKMSCHNTOL", OracleType.NVarChar).Value = dwData["QGKMSCHNTOL"].ToString(); 
          or1.Parameters.Add("QGKFILLER", OracleType.NVarChar).Value = dwData["QGKFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
